package com.web.notice.dao;

import javax.annotation.Resource;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.web.notice.po.DocumentPo;
import com.web.notice.service.DocumentService;

@Service("documentService")
@Transactional(rollbackFor = { Exception.class })
public class DocumentDAO implements DocumentService {

	@Resource 
	private SessionFactory sessionFactory;
	
	public DocumentPo getDocumentPoByDocumentId(Integer documentId) {
		// TODO Auto-generated method stub
		Session session = null;
      	try {
      		 session = this.sessionFactory.getCurrentSession();
             return (DocumentPo) session.get(DocumentPo.class, documentId);
      	} catch (Exception e) {
      		e.printStackTrace();
      		throw new RuntimeException();
		}
	}

	public boolean deleteDocumentPoByDocumentPo(DocumentPo documentPo) {
		// TODO Auto-generated method stub
		Session session = null;
      	try {
      		 session = this.sessionFactory.getCurrentSession();
      		 session.delete(documentPo);
             return true;
      	} catch (Exception e) {
      		e.printStackTrace();
      		throw new RuntimeException();
		}
	}

}
